define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'deposit/index' + location.search,
                    add_url: 'deposit/add',
                    edit_url: 'deposit/edit',
                    del_url: 'deposit/del',
                    multi_url: 'deposit/multi',
                    table: 'user_deposit',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showExport:false,
                searchFormVisible: true,
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},

                        {field: 'wechantNickname', title: __('Wechantnickname'),operate:false},
                        {field: 'iphone', title: __('Iphone')},
                        {field: 'cash_fee', title: __('Cash_fee'),operate:false},
                        {field: 'weChatCcount', title: __('Wechatccount'),operate:false},
                        {field: 'money', title: __('Money'),operate:false},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4')}, formatter: Table.api.formatter.status},
                        {field: 'moneylog_id', title: __('Moneylog_id'),operate:false},
                        // {field: 'reviewuser_id', title: __('Reviewuser_id'),operate:false},
                        {field: 'reviewtime', title: __('Reviewtime') ,operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'),operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'remark', title: __('Remark'),operate:false},
                        // {field: 'user.nickname', title: __('User.nickname')},
                        {field: 'operate', title: __('Operate'),
                            buttons: [

                                {
                                    name: 'detail',
                                    width: "80px",
                                    height:'50px',
                                    title: __('审核'),
                                    text: __('审核'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'deposit/detail',
                                    callback: function (data) {

                                        Fast.api.ajax({
                                            url:'deposit/up',
                                            data:{
                                                id:data.id,
                                                status:data.status
                                            },

                                        }, function(datat, ret){
                                            //成功的回调
                                            Layer.alert( ret.msg, {title: "审核"});
                                            $('.btn-refresh').trigger('click');
                                        }, function(data, ret){
                                            //失败的回调
                                            Layer.alert( ret.msg, {title: "审核"});
                                        });

                                    },
                                    extend: 'data-area=["350px", "350px"]',
                                    visible: function (row) {
                                        if(row.status==2||row.status==3){
                                            return false;
                                        }else{
                                            return true;
                                        }
                                    },
                                }
                            ],

                            table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        detail: function () {
            $(document).on('click', '.btn-callback', function () {
                // alert($("input[type='radio']:checked").val())
                var data={};
                data.status=$("input[type='radio']:checked").val();
                data.id=$("input[name=id]").val();
                Fast.api.close(data);
            });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});